//
//  LBMediaPresentViewController.m
//  LangBa
//
//  Created by Mac on 2017/12/21.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "LGPayPresentViewController.h"
#import "STPasswordTextField.h"
@interface LGPayPresentViewController ()
@property(nonatomic, strong) STButton                     *clearButton;
@property(nonatomic, strong) UIView                     *customView;
@property(nonatomic, strong) STLabel                     *allBiLable;
@property(nonatomic, strong) STLabel                     *payLable;
@property(nonatomic, strong) STLabel                     *yueLable;
@end

@implementation LGPayPresentViewController

- (instancetype)init
{
    if (self == [super init]) {
        self.modalPresentationStyle = UIModalPresentationOverFullScreen;
    }
    return self;
}
#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
    [self configSubView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self show];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    self.clearButton = [[STButton alloc] initWithFrame:UIScreenFrame
                                                 title:nil
                                            titleColor:nil
                                             titleFont:0
                                          cornerRadius:0
                                       backgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.4]
                                       backgroundImage:nil
                                                 image:nil];
    [weakSelf.clearButton setClicAction:^(UIButton *sender) {
        [weakSelf dismissViewControllerAnimated:NO completion:nil];
    }];
    [self.view addSubview:_clearButton];
    
    self.customView = [[UIView alloc] initWithFrame:CGRectMake(0, UIScreenHeight, UIScreenWidth - 60, 342)];
    self.customView.centerX = UIScreenWidth / 2;
    self.customView.top = UIScreenHeight;
    self.customView.backgroundColor = [UIColor whiteColor];
    self.customView.layer.cornerRadius = 10;
    self.customView.clipsToBounds = YES;
    self.customView.centerY = UIScreenHeight / 2;
    [self.view addSubview:self.customView];
    
    UIImageView * imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.customView.width, 200)];
    imageview.image = [UIImage imageNamed:@"首页bg"];
    imageview.userInteractionEnabled = YES;
    [self.customView addSubview:imageview];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0,0, self.customView.width, 50)
                                                     text:@"确认支付"
                                                textColor:FlatRed
                                                     font:18
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [self.customView addSubview:titleLable];
    
    UIView * line1 = [[UIView alloc] initWithFrame:CGRectMake(0, titleLable.bottom, self.customView.width, 0.5)];
    line1.backgroundColor = TM_lineColor;
    [self.customView addSubview:line1];
    
    STLabel * desLable = [self lableWithTitle:@"账户总额"];
    desLable.top = line1.bottom;
    [self.customView addSubview:desLable];
    
    
    STLabel * desmoneyLable = [self moneylableWithTitle:@"1000礼根币"];
    desmoneyLable.top = line1.bottom;
    self.allBiLable = desmoneyLable;
    [self.customView addSubview:desmoneyLable];
    
    UIView * line2 = [[UIView alloc] initWithFrame:CGRectMake(0, desmoneyLable.bottom, self.customView.width, 0.5)];
    line2.backgroundColor = TM_lineColor;
    [self.customView addSubview:line2];
    
    STLabel * payLable = [self lableWithTitle:@"您将支付"];
    payLable.top = line2.bottom;
    [self.customView addSubview:payLable];
    
    
    STLabel * payLablemoneyLable = [self moneylableWithTitle:@"1000礼根币"];
    payLablemoneyLable.top = line2.bottom;
    self.payLable = payLable;
    [self.customView addSubview:payLablemoneyLable];
    
    
    UIView * line3 = [[UIView alloc] initWithFrame:CGRectMake(0, payLable.bottom, self.customView.width, 0.5)];
    line3.backgroundColor = TM_lineColor;
    [self.customView addSubview:line3];
    
    STLabel * yueLable = [self lableWithTitle:@"账户余额"];
    yueLable.top = line3.bottom;
    [self.customView addSubview:yueLable];
    
    
    STLabel * yueLablemoneyLable = [self moneylableWithTitle:@"0礼根币"];
    yueLablemoneyLable.top = line3.bottom;
    self.yueLable = yueLablemoneyLable;
    [self.customView addSubview:yueLablemoneyLable];
    
    
    UIView * line4 = [[UIView alloc] initWithFrame:CGRectMake(0, yueLablemoneyLable.bottom, self.customView.width, 0.5)];
    line4.backgroundColor = TM_lineColor;
    [self.customView addSubview:line4];
    
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(0, line4.bottom + 15, 77, 34)
                                                     title:@"确认"
                                                titleColor:[UIColor whiteColor]
                                                 titleFont:14
                                              cornerRadius:4
                                           backgroundColor:FlatRed
                                           backgroundImage:nil
                                                     image:nil];
    confimButton.right = self.customView.width / 2 - 15;
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf dismissWithHandle:^{
            
        }];
    }];
    [self.customView addSubview:confimButton];
    
    
    STButton * concleButton = [[STButton alloc] initWithFrame:CGRectMake(0, line4.bottom + 15, 77, 34)
                                                        title:@"取消"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:14
                                                 cornerRadius:4
                                              backgroundColor:FlatGray
                                              backgroundImage:nil
                                                        image:nil];
    concleButton.left = self.customView.width / 2 + 15;
    concleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [concleButton setClicAction:^(UIButton *sender) {
        [weakSelf dismiss];
    }];
    [self.customView addSubview:concleButton];
    
    self.customView.height = concleButton.bottom + 15;
    imageview.height = self.customView.height;
    
   self.customView.top = UIScreenHeight ;
}
- (STLabel*)lableWithTitle:(NSString*)title{
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(20, 0, 200, 44)
                                                     text:title
                                                textColor:SecendTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    return titleLable;
}
- (STLabel*)moneylableWithTitle:(NSString*)title{
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)
                                                     text:title
                                                textColor:FlatRed
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentRight];
    titleLable.right = self.customView.width - 20;
    return titleLable;
}
#pragma mark --Private Method
- (void)show{
    [UIView animateWithDuration:0.6
                          delay:0
         usingSpringWithDamping:0.6
          initialSpringVelocity:0.7
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                          self.customView.centerY = UIScreenHeight / 2;
                     } completion:^(BOOL finished) {
                         
                     }];
}
- (void)dismiss{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}
- (void)dismissWithHandle:(void(^)())handle{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
            if (handle) {
                handle();
            }
        }];
    }];
}
#pragma mark --Action Method

- (void)onSelectedCancleButton{
    
    [self dismiss];
    
}
- (void)onSelectedWhiteView{
    [self.view endEditing:YES];
}

@end





